<%@page import="net.sf.ehcache.CacheManager"%>
<%@page contentType="text/html; charset=UTF-8" session="false"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@page import="net.sf.ehcache.Cache"%>
<%@page import="java.io.File"%>
<%@page import="net.sf.ehcache.Statistics"%>
<%
	String caption = "缓存管理";
	String op = request.getParameter("op");
	if (op != null) {
		if (op.equals("clearDataCache")) {
			String cacheName = request.getParameter("cacheName");
			if (cacheName != null) {
				net.sf.ehcache.CacheManager.getInstance().removeCache(cacheName);
			}
		} else if (op.equals("clearAllDataCache")) {
			net.sf.ehcache.CacheManager.getInstance().clearAll();
		}
		response.sendRedirect("index.jsp");
		return;
	}
%>
<%@ include file="header.jsp"%>
<%@page import="com.zhangyj.cache.DataCacheManager"%><span class="title">数据缓存信息</span>:
<table cellpadding="6" style="border: solid 1px #80a0c0 width:450px; border-collapse: collapse; text-align: center;" border="1" cellspacing="0" borderColor="#C0C0C0">
	<tr style="background-color:#f8f8f8; font-weight:bold;">
		<td width="200px">缓存名称</td>
		<td width="60px">缓存总数</td>
		<td width="60px">内存缓冲表单数</td>
		<td width="60px">磁盘缓冲表单数</td>
		<td width="60px">读取命中次数</td>
		<td width="60px">读取内存命中次数</td>
		<td width="60px">读取磁盘命中次数</td>
		<td width="100px">操作</td>
	</tr>
<%
	Map<String, String> descMap = new HashMap<String, String>();
	String[] names = CacheManager.getInstance().getCacheNames();
	
	for (int i = 0; i < names.length; i++) {
		Cache cache = CacheManager.getInstance().getCache(names[i]);
		Statistics stat = cache.getStatistics();
%>
	<tr>
		<td width="200px" style="text-align:left"><b><%=cache.getName()%></b></td>
		<td width="40px"><%=cache.getSize()%></td>
		<td width="60px"><%=cache.getMemoryStoreSize()%></td>
		<td width="60px"><%=cache.getDiskStoreSize()%></td>
		<td width="60px"><%=stat.getCacheHits()%></td>
		<td width="60px"><%=stat.getInMemoryHits()%></td>
		<td width="60px"><%=stat.getOnDiskHits()%></td>
		<td rowspan="2" width="80px" style="border-bottom: dotted 1px #80a0c0; border-left: dotted 1px #80a0c0;"><input type="button" value="清除缓存" onclick="javascript:window.location='index.jsp?op=clearDataCache&cacheName=<%=cache.getName()%>';"/></td>
	</tr>
<%
		String desc = descMap.get(cache.getName());
		if (desc == null)
			desc = "";
%>
	<tr>
		<td colspan="7" style="font-size: 13px; color:#808080; border-bottom: dotted 1px #80a0c0; text-align:left">&nbsp;&nbsp;<%=desc%></td>
	</tr>
<%			
	}
%>	
<tr>
	<td colspan="8" align="center"><input type="button" value="清除所有缓存" onclick="javascript:window.location='<%=request.getContextPath()%>/cachemanage/index.jsp?op=clearAllDataCache';"/></td>
</tr>	
</table>
<%@ include file="footer.jsp"%>

